import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

// element ui配置
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

// axios全局配置
import axios from "axios";
const BASEURL = (process.env.NODE_ENV === 'production') ? 'http://120.79.0.124:8092' : 'http://localhost:8092';
const http = axios.create({
    baseURL: BASEURL+'/api', //设置服务器访问的域名。
    timeout: 60000,//超时时间
    headers: { //默认所有数据都是json传递
        "Content-Type": "application/json;charset=UTF-8",
        "Access-Control-Allow-Methods": "*"
    },
});
// 添加请求拦截器。主要是用于处理token
http.interceptors.request.use(
    config => {
        //读取token
        const token = localStorage.getItem("token");
        if (token) {
            config.headers.access_token = token;// 让头部携带token
        }
        return config;
    },
    error => Promise.resolve(error.response),
);
//挂在在vue的原型上
Vue.prototype.$axios = http; //这样在项目中可以通过this.$axios使用axios插件


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

